package cn.exempale.mscapplication.model.db.database;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.DatabaseConfiguration;
import androidx.room.InvalidationTracker;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;
import androidx.sqlite.db.SupportSQLiteOpenHelper;

import cn.exempale.mscapplication.model.db.converters.DateConvert;
import cn.exempale.mscapplication.model.db.dao.ResultDAO;
import cn.exempale.mscapplication.model.db.dao.TaskDAO;
import cn.exempale.mscapplication.model.db.entity.ResultEntity;
import cn.exempale.mscapplication.model.db.entity.TaskEntity;


@Database(entities = {TaskEntity.class, ResultEntity.class}, version = 1)
@TypeConverters({DateConvert.class})
public abstract class AudioDb extends RoomDatabase {

    /**
     * DAO
     */
    public abstract TaskDAO taskDAO();

    public abstract ResultDAO resultDAO();

    /**
     * 实现单实例
     */
    private static volatile AudioDb INSTANCE;

    public static AudioDb getDatabase(Context context) {
        if (INSTANCE == null) {
            synchronized (AudioDb.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(), AudioDb.class,
                            "audio_database").build();
                }
            }
        }
        return INSTANCE;
    }

    @NonNull
    @Override
    protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration config) {
        return null;
    }

    @NonNull
    @Override
    protected InvalidationTracker createInvalidationTracker() {
        return null;
    }

    @Override
    public void clearAllTables() {

    }
}
